package com.wn.cl.park.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.Getter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 封装支付宝中参数实体类
 */
@Configuration
//读取这个属性文件
//@PropertySource("classpath:config/alipay.properties")
@Getter
public class AlipayConfig {
 /*   @Value("${ali.serverUrl}")
    private String serverUrl;
    @Value("${ali.appId}")
    private String appId;
    @Value("${ali.alipayPublicKey}")
    private String alipayPublicKey;
    @Value("${ali.privateKey}")
    private String privateKey;
    @Value("${ali.returnUrl}")
    private String returnUrl; // 支付成功返回的页面
    @Value("${ali.notifyUrl}")
    private String notifyUrl; // 支付宝支付成功异步回调的页面，需要内网穿透*/


    private String serverUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";

    private String appId = "9021000142686990";

    private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsSeDs890m3No1XEQIBMNGnZv1iZHx8IO7WzeB4VVqHVWYeyNChO5dhJmzWYmCM5kOVZgSqFitdSMQTS1P2QbgHvR/AeIrpU3IAAcKCTB6jcxKRbkACM/a+0VxItZEXHoV1Q0Fput0OFe+zcTMeLJiWwb7XQ4u3jRr4+ypCMJbOho6Xs6geVdEXLkTTGKcYZ3MIcHAAygvO8Hd5okxtkqyIxBzZ4rFmajFWJaJBAOKnpWQupyUB8yMtkTVjyRYxZzY4Ua8kGMLC7Y8sf/7ekolRHucajUSt4RNxnaQHk8AASGojTr/xAAXNmv5lAGeRsVYendEzbjf6N7FTog2rCAOQIDAQAB";

    private String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCAfYB6MARv5R9qik7j9i2xQ7HMj4kpj+QG90x1+z9eZjgYnib7+mxwKzm/wcF+RPIlFZzfNiiQGwi0K4T+3ymJb772wXLdGVHgU8qyuBiGwg4GZ+IMzOb40YjGET4Uq3bapm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BAoGAbggnWky7xKQ3R37OvCDaTo43F4dRZKNTpaUfQUyInro0lrWPkMDBQ2DxZzREcxaKSufFGm0BRNhf3b/KulMNI2Geulsy+hRv7f2Azz3EfJptI8yKuVRsUAx3GfJlvntezREdP5A1pP7r3zi4VX09urJ9/fT2wQz5Ch24SiSarBkCgYEAj5kZJ3WcGSsuuPhVQMXvMyr1/WAzYGNFxjKoBmfC8tkpiM1O7k1L+jI4h4jAJQLfqBTCpQcNwZd4wmYKQNwFWG4jbFxwdRhFXSScbMOONtnj0COsoMWbNW6sp4K1jmtma92rejEnjh9KQfOU3LtpoiO8m/4FFKXFwYuT0hU8Rws=";

    private String returnUrl = "https://www.baidu.com/"; // 支付成功返回的页面

    private String notifyUrl = "http://rdnka7.natappfree.cc/payments/notify" ; // 支付宝支付成功异步回调的页面，需要内网穿透



    /**
     * 创建客户端对象
     * @return
     * @throws AlipayApiException
     */
    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        // 2.把需要配置的参数set进AlipayConfig类中
        com.alipay.api.AlipayConfig alipayConfig = new com.alipay.api.AlipayConfig();
        alipayConfig.setServerUrl(serverUrl);
        alipayConfig.setAppId(appId);
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF8");
        alipayConfig.setSignType("RSA2");
        return new DefaultAlipayClient(alipayConfig);
    }
}